
# Contents: Song.rb
# Purpose: To provide a Song Data object
# Status: Complete

require 'Make_Hash'

class Song
	def initialize( filepath,artist,album,title,duration,hash,playcount,rating,last_played)
		@artist = artist
		@album = album
		@title = title
		@duration = duration
		if ((hash == nil || hash == "") && FileTest.exist?(filepath))
			@hash = Song.make_hash(filepath)
		else
			@hash = hash
		end
		@playcount = playcount
		@rating = rating
		@last_played = last_played
		@filepath = filepath

		if (playcount == "") or (playcount == nil)
			@playcount = 0
		else
			@playcount = playcount.to_i
		end
		if rating  == "" or rating == nil
			@rating = 0.0
		end
	end

	def filepath
		@filepath
	end
	
	def set_filepath(f)
		@filepath = f
	end
	
	def artist
		@artist
	end
  
	def set_artist(a)
		@artist = a
  	end

	def album
		@album
	end
  
	def set_album(a)
		@album = a
	end

	def title
		@title
	end
  
	def set_title(t)
		@title = t
	end

	def duration
		@duration
	end
  
	def set_duration(d)
		@duration = d
	end
  
	def hash
		@hash
	end
  
	def set_hash(h)
		@hash = h
  	end

	def playcount
		@playcount
	end
  
	def set_playcount(pc)
		@playcount = pc
	end

	def rating
		@rating
	end
  
	def set_rating (r)
		@rating=r
	end
  
	def last_played
		@last_played
	end
   
	def set_last_played(lp)
		@last_played = lp
	end
	
	def increment_playcount
		if (@playcount != nil )
			@playcount = @playcount.to_i + 1
		else
			@playcount = 1
		end
		@last_played = Time.new.strftime("%Y%m%d %H:%M:%S")
	end
  
	def increase_playcount (pc)
		@playcount = @playcount + pc
	end
  
	def to_s
		return "Song Info: \r\n\tArtist: #{artist}\r\n\tAlbum: #{@album}\r\n\tTitle: #{@title}\r\n\tPlay Count: #{playcount}\r\n\tRating: #{rating}"
	end
  
  def to_response
    return  "\"#{filepath}\" \"#{artist}\" \"#{album}\" \"#{title}\" \"#{duration}\" \"#{hash}\" \"#{playcount}\" \"#{rating}\" \"#{last_played}\""
  end
end
